package com.duoec.magichour.core.web;

import com.duoec.magichour.core.exceptions.BusinessException;
import com.duoec.magichour.dto.BaseResponse;
import com.duoec.magichour.dto.UserInfo;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * Created by ycoe on 17/6/25.
 */
public class BaseApiController {
    protected UserInfo getUserInfo() {
        return UserInfoHolder.get();
    }

    @ExceptionHandler({BusinessException.class})
    public BaseResponse handleException(BusinessException e) {
        return BaseResponse.error(e.getCode(), e.getMessage());
    }
}
